#include "IncomingWidget.h"
#include "ui_IncomingWidget.h"
#include <QDesktopWidget>

#include <QDebug>
#include "smartphone/Smartphone.h"

IncomingWidget::IncomingWidget(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::IncomingWidget)
{
    ui->setupUi(this);
    this->setAttribute(Qt::WA_QuitOnClose, false);
    this->setAutoFillBackground(true);
    mBackPixmap = QPixmap(":/images/bk/bk_incomingwidget.png");
    setBackgroundImage(mBackPixmap);

    this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); //隐藏菜单栏
    int screenWidth = QApplication::desktop()->screenGeometry().width();
    int screenHeight =  QApplication::desktop()->screenGeometry().height();
    int availableHeight =  QApplication::desktop()->availableGeometry().height();
        this->setGeometry(0, 0, screenWidth / 5, screenHeight / 7);
    this->move(screenWidth - this->width(), availableHeight - this->height());

}
void IncomingWidget::setBackgroundImage(QPixmap &pixmap)
{
    if(pixmap.isNull())
    {
        qDebug()<<"illege argument"<<endl;

        return;
    }
    QPalette palette = this->palette();
    palette.setBrush(this->backgroundRole(),QBrush(pixmap.scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
    this->setPalette(palette);
}
IncomingWidget::~IncomingWidget()
{
    delete ui;
}
void IncomingWidget::setDispname(QString dispname)
{
    ui->lDispname->setText(dispname);
}
void IncomingWidget::setUsername(QString username)
{
    ui->lUsername->setText(username);
}

void IncomingWidget::on_btnDecline_clicked()
{
    Smartphone::getInstance()->terminate(Smartphone::getInstance()->getCurrentCallid());
    this->hide();
}

void IncomingWidget::on_btnAcceptAudio_clicked()
{
    MediaType mt = MediaTypeAudio;
    Smartphone::getInstance()->answer(Smartphone::getInstance()->getCurrentCallid(), mt, MediaDirectionSendRecv, MediaDirectionSendRecv);
    this->hide();
}

void IncomingWidget::on_btnAcceptVideo_clicked()
{
    MediaType mt = MediaTypeAudioVideo;
    Smartphone::getInstance()->answer(Smartphone::getInstance()->getCurrentCallid(), mt, MediaDirectionSendRecv, MediaDirectionSendRecv);
    this->hide();
}
